package cn.mengfly.product;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.web.client.RestTemplate;

/**
 * EnableDiscoveryClient 注解表示这是一个微服务提供者，会自动连接Eureka服务器进行服务注册
 * <p>
 * EnableFeignClient 表示启用Feign环境，然后就可以使用Feign来进行微服务访问了
 * <p>
 * EnableCircuitBreaker 标识需要在项目中使用Netflix的Hystrix库
 *
 * @author Mengfly
 * @date 2021/3/10 19:30
 */
@EnableCircuitBreaker
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
@EnableHystrixDashboard
@EnableResourceServer
public class Application {

    /**
     * LoadBalanced 标识让restTemplate 具有负载均衡的功能
     */
    @LoadBalanced
    @Bean(value = "restTemplate")
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
